package com.ruoyi.prod.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.prod.domain.TbProd;
import com.ruoyi.prod.service.ITbProdService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商品列表Controller
 * 
 * @author ruoyi
 * @date 2025-08-02
 */
@RestController
@RequestMapping("/prod")
public class TbProdController extends BaseController
{
    @Autowired
    private ITbProdService tbProdService;
    @Autowired
    HttpServletRequest request;

    /**
     * 查询商品列表列表
     */

//    @RequiresPermissions("prod:prod:list")
//    @GetMapping("/list")
//    public TableDataInfo list(TbProd tbProd)
//    {
//        startPage();
//        List<TbProd> list = tbProdService.selectTbProdList(tbProd);
//        return getDataTable(list);
//    }
    @RequiresPermissions("prod:prod:list")
    @GetMapping("/list")
    public TableDataInfo list(TbProd tbProd)
    {
        String pageNum = request.getParameter("pageNum");
        String pageSize = request.getParameter("pageSize");

        return  tbProdService.getProdList(tbProd,Integer.valueOf(pageNum),Integer.valueOf(pageSize));
    }
    /**
     * 导出商品列表列表
     */
    @RequiresPermissions("prod:prod:export")
    @Log(title = "商品列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbProd tbProd)
    {
        List<TbProd> list = tbProdService.selectTbProdList(tbProd);
        ExcelUtil<TbProd> util = new ExcelUtil<TbProd>(TbProd.class);
        util.exportExcel(response, list, "商品列表数据");
    }

    /**
     * 获取商品列表详细信息
     */
    @RequiresPermissions("prod:prod:query")
    @GetMapping(value = "/{prodId}")
    public AjaxResult getInfo(@PathVariable("prodId") Integer prodId)
    {
        return success(tbProdService.selectTbProdByProdId(prodId));
    }

    /**
     * 新增商品列表
     */
    @RequiresPermissions("prod:prod:add")
    @Log(title = "商品列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbProd tbProd)
    {
        return toAjax(tbProdService.insertTbProd(tbProd));
    }

    /**
     * 修改商品列表
     */
    @RequiresPermissions("prod:prod:edit")
    @Log(title = "商品列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbProd tbProd)
    {
        return toAjax(tbProdService.updateTbProd(tbProd));
    }

    /**
     * 删除商品列表
     */
    @RequiresPermissions("prod:prod:remove")
    @Log(title = "商品列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{prodIds}")
    public AjaxResult remove(@PathVariable Integer[] prodIds)
    {
        return toAjax(tbProdService.deleteTbProdByProdIds(prodIds));
    }
}
